package com.example.administrator.libraryclub.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.libraryclub.R;
import com.example.administrator.libraryclub.fragment.adapter.MyFragmentPagerAdapter;

import java.util.List;

/**
 * Created by Administrator on 2015/10/23.
 */
public class ViewPagerFragment extends Fragment {

    /*private ViewPager viewPager;

    private List<Fragment> fragmentsList;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.viewpager_layout, container, false);
        initViews(view);

        return view;
    }

    private void initViews(View view) {
        viewPager = (ViewPager) view.findViewWithTag(R.id.viewpager);
        viewPager.setAdapter(new MyFragmentPagerAdapter(getFragmentManager(), fragmentsList));
        viewPager.setCurrentItem(0);
        viewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    }
    public class MyOnPageChangeListener implements ViewPager.OnPageChangeListener {

        @Override
        public void onPageSelected(int arg0) {
            Animation animation = null;
            switch (arg0) {
                case 0:
                    if (currIndex == 1) {
                        animation = new TranslateAnimation(position_one, 0, 0, 0);
                        tvTabGroups.setTextColor(resources.getColor(R.color.lightwhite));
                    } else if (currIndex == 2) {
                        animation = new TranslateAnimation(position_two, 0, 0, 0);
                        tvTabFriends.setTextColor(resources.getColor(R.color.lightwhite));
                    } else if (currIndex == 3) {
                        animation = new TranslateAnimation(position_three, 0, 0, 0);
                        tvTabChat.setTextColor(resources.getColor(R.color.lightwhite));
                    }
                    tvTabActivity.setTextColor(resources.getColor(R.color.white));
                    break;
                case 1:
                    if (currIndex == 0) {
                        animation = new TranslateAnimation(0, position_one, 0, 0);
                        tvTabActivity.setTextColor(resources.getColor(R.color.lightwhite));
                    } else if (currIndex == 2) {
                        animation = new TranslateAnimation(position_two, position_one, 0, 0);
                        tvTabFriends.setTextColor(resources.getColor(R.color.lightwhite));
                    } else if (currIndex == 3) {
                        animation = new TranslateAnimation(position_three, position_one, 0, 0);
                        tvTabChat.setTextColor(resources.getColor(R.color.lightwhite));
                    }
                    tvTabGroups.setTextColor(resources.getColor(R.color.white));
                    break;
                case 2:
                    if (currIndex == 0) {
                        animation = new TranslateAnimation(0, position_two, 0, 0);
                        tvTabActivity.setTextColor(resources.getColor(R.color.lightwhite));
                    } else if (currIndex == 1) {
                        animation = new TranslateAnimation(position_one, position_two, 0, 0);
                        tvTabGroups.setTextColor(resources.getColor(R.color.lightwhite));
                    } else if (currIndex == 3) {
                        animation = new TranslateAnimation(position_three, position_two, 0, 0);
                        tvTabChat.setTextColor(resources.getColor(R.color.lightwhite));
                    }
                    tvTabFriends.setTextColor(resources.getColor(R.color.white));
                    break;
                case 3:
                    if (currIndex == 0) {
                        animation = new TranslateAnimation(0, position_three, 0, 0);
                        tvTabActivity.setTextColor(resources.getColor(R.color.lightwhite));
                    } else if (currIndex == 1) {
                        animation = new TranslateAnimation(position_one, position_three, 0, 0);
                        tvTabGroups.setTextColor(resources.getColor(R.color.lightwhite));
                    } else if (currIndex == 2) {
                        animation = new TranslateAnimation(position_two, position_three, 0, 0);
                        tvTabFriends.setTextColor(resources.getColor(R.color.lightwhite));
                    }
                    tvTabChat.setTextColor(resources.getColor(R.color.white));
                    break;
            }
            currIndex = arg0;
            animation.setFillAfter(true);
            animation.setDuration(300);
            ivBottomLine.startAnimation(animation);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    }*/

}
